#define _CRT_SECURE_NO_WARNINGS 1
#include<iostream>
#include<string>
using namespace std;
class Solution 
{
public:
    string reverseWords(string s)
    {
        int posprev = 0, pos = 0;
        int length = s.size() - 1;
        while (posprev != string::npos)
        {
            posprev = s.find(' ', pos);
            if (posprev == string::npos)
                break;
            reverse(s.begin() + pos, s.begin() + posprev);
            pos = posprev + 1;
        }
        reverse(s.begin() + pos, s.end());
        return s;
    }
};
int main()
{
    string c = "Let's take LeetCode contest";
    Solution s;
    cout << s.reverseWords(c)<<endl;
	return 0;
}